import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * 名字的漂亮度
 * Created by JiaJia on 2019/6/27 0027.
 */
public class HuaWei040 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            List<String> list=new ArrayList<>();
            while ((--n)>=0){
                list.add(scanner.next());
            }
            System.out.println(count(list));
        }scanner.close();
    }
    private static String count(List<String> list){
        StringBuilder builder=new StringBuilder();
        for (String s:list){
            int result=0;
            int[] seq=new int[26];

            for (int i = 0; i <s.length() ; i++) {
                char c=s.charAt(i);
                if (c >= 'a' && c <= 'z'){
                    seq[c-'a']++;
                }else {
                    seq[c-'A']++;
                }
            }

            Arrays.sort(seq);

            for (int i = 0; i <seq.length ; i++) {
                result+=seq[i]*(i+1);
            }

            builder.append(result).append("\n");
        }
        return builder.toString();
    }
}